import sun.misc.Unsafe
import java.lang.reflect.Field

fun main(args: Array<String>){
    val unsafe=try {
        val field: Field = Unsafe::class.java.getDeclaredField("theUnsafe")
        field.setAccessible(true)
        field.get(null) as Unsafe
    } catch (e: Exception) {
        e.printStackTrace()
        throw e
    }
    // unsafe allocateInstance不会调用构造函数
    val instance =unsafe.allocateInstance(UnsafeTest::class.java) as UnsafeTest
    instance.sayHello()
    // 此时未初始化instance.name 会打印一个null
    println(instance.name)

}


class UnsafeTest(
    val name:String
){
    fun sayHello() {
        println("Hello World!")
    }



    init {
        println("雷霆降生")
    }
}